var tabHeight;
/*=================================*/
    function contentHeight(){
        $('#tab_home_content').height($('html').height()-$('#navbar').height()-$('#tab_tablist').height()-80);
    }
function adjustContentHeight(obj){
    $(obj).height($('html').height()-$('#navbar').height()-$('#tab_tablist').height()-80);
}
/*=================================*/
$(function(){
	tabHeight = $(window).height()-$('#navbar').height()-$('#tab_tablist').height()-64-15;
	$('#actionUl').delegate("a","click",function(){showNewTab(this);});
	var contentId = 'tab_home_content';
	var menu = '首页';
	var tabId = 'tab_home';
	var url = headpage;
	var id = '-1';
	$('#mainDiv').append(
			'<ul class="nav nav-tabs" role="tablist" id="tab_tablist">\
				<li role="presentation">\
				 <a href="#'+contentId+'" aria-controls="'+contentId+'" title="'+menu+'" role="tab" data-toggle="tab" id='+tabId+' class="tab_menu">'+menu+'</a>\
				</li>\
			</ul>\
			<div class="tab-content content-full" id="tab_content" style="background:#fff;"> \
			<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;" >\
				<iframe frameborder="0" width="100%" height="100%" src="'+url+'" id="content_iframe_home"/>\
			</div>\
			</div>'		
		);
	contentHeight();
	$("#hidemenu").hide();
	$("#navbar-hide").click(function(){
		$("#navbar").fadeToggle();
		$("#hidemenu").fadeToggle();
	});
	$("#navbar-show").click(function(){
		$("#navbar").fadeToggle();
		$("#hidemenu").fadeToggle();
	});
	$('#'+tabId).click();
});
function showNewTab(obj){
	var id =$(obj).attr('id');
	var menu = $(obj).text();
	var url = $(obj).attr('data-info');
	if(!url || '' == url || '#' == url){
		return;
	}
	var tabId = "tab_"+id;
	if($('#'+tabId).size() == 0){
		var contentId = 'content_'+id;
		url = frmPrefix+url;
		$('#tab_tablist').append(
			'<li role="presentation">'+
			' <a href="#'+contentId+'" aria-controls="'+contentId+'" title="'+menu+'" role="tab" data-toggle="tab" id='+tabId+' class="tab_menu">'+menu+'</a>'+
			' <span style="cursor:pointer;color:#AAAAAA" class="fa fa-close tab-close" aria-hidden="true" id="btnClose_'+id+'" onclick="close_tab(this.id)" ></span>'+
			'</li>'
		);
		$('#tab_content').append(
			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;"></div>'
		);
		$('#content_'+id).append('<iframe frameborder="0" width="100%" height="100%" src="'+url+'"/>');
	}
	$('#'+tabId).click();
	if(adjustContentHeight)
		adjustContentHeight($("#"+contentId));
}

// 展示标签页
//function showTab(id,menu,url){
//	var tabId = "tab_"+id;
//	if($('#'+tabId).size() == 0){
//		var contentId = 'content_'+id;
//		url = frmPrefix+url;
//		$('#tab_tablist').append(
//			'<li role="presentation">'+
//			' <a href="#'+contentId+'" aria-controls="'+contentId+'" role="tab" data-toggle="tab" id='+tabId+' style="padding-right: 20px;">'+menu+'</a>'+
//			' <span class="glyphicon glyphicon-remove-circle tab-close" aria-hidden="true" id="btnClose_'+id+'" onclick="close_tab(this.id)" ></span>'+
//			'</li>'
//		);
//		$('#tab_content').append(
//			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;"></div>'
//		);
//		$('#content_'+id).append('<iframe frameborder="0" width="100%" height="100%" src="'+url+'"/>');
//	}
//	$('#'+tabId).click();
//}

function menu(data,pid){
	var menus=data;
	var ulmain= $("#"+pid);
	$.each(menus,function(index,menuinfo){
		if(!jQuery.isEmptyObject(menuinfo.childrens)){
			ulmain.append("<li class='' id="+menuinfo.id+"></li>");
			$("#"+menuinfo.id).append("<a class='dropdown-toggle'  href='#'"+"id="+menuinfo.id+"a"+" data-info="+menuinfo.uri+" ></a>");
			$("#"+menuinfo.id+"a").append("<span class='menu-icon "+((menuinfo.icon==''||menuinfo.icon==null)?"menu-icon fa fa-desktop":menuinfo.icon)+"'></span>");
			$("#"+menuinfo.id+"a").append("<span class='menu-text'> "+menuinfo.name+" </span>");
			$("#"+menuinfo.id+"a").append("<b class='arrow fa fa-angle-down'></b>");
			$("#"+menuinfo.id).append("<b class='arrow'></b>");
			$("#"+menuinfo.id).append("<ul class='submenu'"+" id="+menuinfo.id+"ul"+"></ul>");
			var parent=menuinfo.id+"ul";
			menu(menuinfo.childrens,parent);
		}else{
			ulmain.append("<li class='' id="+menuinfo.id+"></li>");
			$("#"+menuinfo.id).append("<a class='dropdown-toggle'  href='#'"+"id="+menuinfo.id+"a"+" data-info="+menuinfo.uri+" ></a>");
			$("#"+menuinfo.id+"a").append("<span class='menu-icon "+((menuinfo.icon==''||menuinfo.icon==null)?"fa fa-caret-right":menuinfo.icon)+"'></span>");
			$("#"+menuinfo.id+"a").append("<span class='menu-text'>"+menuinfo.name+"</span>");
			$("#"+menuinfo.id).append("<b class='arrow'></b>");
		};
		});
	}
$(function(){
	menu(menus,"actionUl");
});
// 关闭tab页
function close_tab(id){
	$('#'+id).parent().remove();
	id = 'content'+id.substring(id.indexOf('_'));
	$('#'+id).remove();
	$('#tab_tablist').children().last().children().first().click();
}

// 展示标签页
function showTab(){
	
	$('#changpass').modal('show');
	/*var menu = '更改密码';
	var url = 'sysPasswd.action';
	var id = '-1';
	var tabId = "tab_"+id;
	if($('#'+tabId).size() == 0){
		var contentId = 'content_'+id;
		url = frmPrefix+url;
		$('#tab_tablist').append(
			'<li role="presentation">'+
			' <a href="#'+contentId+'" aria-controls="'+contentId+'" role="tab" data-toggle="tab" id='+tabId+' style="padding-right: 20px;">'+menu+'</a>'+
			' <span class="glyphicon glyphicon-remove-circle tab-close" aria-hidden="true" id="btnClose_'+id+'" onclick="close_tab(this.id)" ></span>'+
			'</li>'
		);
		$('#tab_content').append(
			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;"></div>'
		);
		$('#'+ contentId).append('<iframe frameborder="0" width="100%" height="100%" src="'+url+'"></iframe>'
		);*/


//	}
//	$('#'+tabId).click();
}
